package com.wangrui.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangrui.pojo.Role;
import com.wangrui.mapper.RoleMapper;
import com.wangrui.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 王锐
 * @since 2020-07-05
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> queryAllRolesById() {
        return roleMapper.selectList(null);
    }

    @Override
    public Map<String, Object> queryAllRoles(int start, int end) {
        Page<Role> page = new Page<>(start,end);
        roleMapper.selectPage(page,null);

        Map<String, Object> map = new HashMap<>();

        map.put("total", roleMapper.selectCount(null));
        map.put("rows", page.getRecords());
        return map;
    }

    @Override
    public int roleSave(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int roleUpdate(Role role) {
        return roleMapper.updateById(role);
    }

    @Override
    public int roleDelete(int ids) {
        return roleMapper.deleteById(ids);
    }
}
